/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import common.Application;
import common.Initializer;
import database.DatabaseObject;
import database.DatabaseObjectFactory;
import java.util.Collection;
import java.util.LinkedList;
import runtime.RuntimeInstanceFactory;
import templates.PropertyTemplate;
import templates.Template;

/**
 *
 * @author Alejandro
 */
public class EntityInitializer implements Initializer {

    @Override
    public Object init(Object obj) {
        short uid = (Short) obj;
        Collection<Property> properties = new LinkedList<Property>();
        Application app = Application.getInstance();
        Template template = app.getTemplate(uid);
        Iterable<PropertyTemplate> propertyTemplates = template.getPropertyTemplateCollection();
        RuntimeInstanceFactory factory = new DatabaseObjectFactory();
        for(PropertyTemplate pt: propertyTemplates) {
            DatabaseObject value = (DatabaseObject) factory.getObject(pt.getType());
            properties.add(new Property(pt.getUid(), value));
        }
        return properties;
    }

    @Override
    public void setManagedObject(ObjectType obj) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
}
